package com.algorithm.recursion_multi;

import java.util.LinkedList;

/**
 * 汉诺塔
 * 时间复杂度: O(2^n)
 */
public class E02HanoiTower {
    static LinkedList<Integer> a = new LinkedList<>();
    static LinkedList<Integer> b = new LinkedList<>();
    static LinkedList<Integer> c = new LinkedList<>();


    public static void init(int n) {
        for (int i = n; i > 0; i--) {
            a.addLast(i);
        }
    }

    /**
     * 汉诺塔
     * @param n 圆盘个数
     * @param a 由
     * @param b 借
     * @param c 至
     */
    public static void move(int n,LinkedList<Integer> a,
                            LinkedList<Integer> b,
                            LinkedList<Integer> c) {
        if (n == 0) {
            return;
        }
        move(n - 1, a, c, b);
        c.addLast(a.removeLast());
        print();
        move(n - 1, b, a, c);
    }

    public static void main(String[] args) {
        init(3);
        print();
        move(3, a, b, c);
    }

    private static void print() {
        System.out.println("------------");
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
    }
}
